$(function () {

    /**
     查询安灯事件
     **/
    function getAanEvents() {
        $.ajax({
            // url: '../json/getAanEvents.json',
            url: baseUrl + 'getAanEvents',
            type: 'get',
            // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
            // data: { method: 'getAanEvents' },
        })
            .done(function (data) {
                console.log("getAanEvents");
                var data = data.data;
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    var andonStyle = data[i].andonStyle;
                    switch (andonStyle) {
                        case 1:
                            andonStyle = "设备故障";
                            break;
                        case 2:
                            andonStyle = "技术疑问";
                            break;
                        case 3:
                            andonStyle = "产品质量偏差";
                            break;
                        case 4:
                            andonStyle = "安灯叫料";
                            break;
                    }
                    html += `  <tr>
                                <td class="andonStyle" data-andon="${data[i].andonStyle}">${andonStyle}</td>
                                <td class="productlineNum">${data[i].productlineNum}</td>
                                <td class="processId">${data[i].processId}</td>
                                <td class="deviceNum">${data[i].deviceNum}</td>
                                <td class="startTime">${data[i].startTime}</td>
                                <td class="contact"><input type="text"></td>
                                <td class="tel"><input type="text"></td>
                                <td class="contactContent"><input type="text"></td>
                                <td class="remark"><input type="text"></td>
                                <td><button>确认</button></td>
                            </tr>`;
                }
                $(html).appendTo('.table')
                // console.log(html)

            })
            .fail(function () {
                console.log("error");
            })
    }

    getAanEvents();


    function doAanEvenCom(contact, tel, contactContent, remark, startTime, andonStyle) {
        $.ajax({
            // url: '../json/getAanEvents.json',
            url: baseUrl + 'doAanEvenCom',
            type: 'get',
            // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
            data: {
                // method: 'doAanEvenCom',
                contact: contact,
                tel: tel,
                contactContent: contactContent,
                remark: remark,
                startTime: startTime,
                andonStyle: andonStyle
            }
        })
            .done(function (data) {
                console.log("doAanEvenCom");
                // console.log(html)
                window.location.reload();
            })
            .fail(function () {
                console.log("error");
            })
    }

    $("body").on('click', 'button', function (event) {
        event.preventDefault();
        /* Act on the event */
        var contact = $(this).parent().siblings('.contact').children('input').val();
        var tel = $(this).parent().siblings('.tel').children('input').val();
        var contactContent = $(this).parent().siblings('.contactContent').children('input').val();
        var remark = $(this).parent().siblings('.remark').children('input').val();
        var startTime = $(this).parent().siblings('.startTime').text();
        var andonStyle = Number($(this).parent().siblings('.andonStyle').data("andon"));
        doAanEvenCom(contact, tel, contactContent, remark, startTime, andonStyle);

    });
})